﻿using MediatR;
using SheepCultivation.Common.Domain.main;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;

namespace SheepCultivation.API.AddliCation.Tip_newspaper
{
    public class LambBackSeachHandler : IRequestHandler<LambBackSeachCommon, Result>
    {
        public readonly IBaseRepository<Lamb> LambRepository;
        public LambBackSeachHandler(IBaseRepository<Lamb> lambRepository)
        {
            LambRepository = lambRepository;
        }
        public async Task<Result> Handle(LambBackSeachCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                res.Code = (int)CommonEnumCode.success;
                var list = LambRepository.GetAll().FirstOrDefault(x => x.BreedingSheepArchiveId == request.BreedingSheepArchiveId);
                res.Code = (int)CommonEnumCode.success;
                res.Data = list;
                res.Msg = "羔羊断奶反填";
            }
            catch (Exception)
            {

                throw;
            }
            return res;
        }
    }
}
